package com.huawei.mpchartlib.animation;

import ohos.agp.animation.AnimatorValue.ValueUpdateListener;

/**
 * Object responsible for all animations in the Chart. Animations require API level 11.
 *
 * @author Philipp Jahoda
 * @author Mick Ashton
 */
public class ChartAnimator {

    /** object that is updated upon animation update */
//    private AnimatorUpdateListener mListener;
    private ValueUpdateListener mListener;

    /** The phase of drawn values on the y-axis. 0 - 1 */
    @SuppressWarnings("WeakerAccess")
    protected float mPhaseY = 1f;

    /** The phase of drawn values on the x-axis. 0 - 1 */
    @SuppressWarnings("WeakerAccess")
    protected float mPhaseX = 1f;

    public ChartAnimator() { }

//    @RequiresApi(11)
    public ChartAnimator(ValueUpdateListener listener) {
        mListener = listener;
    }

//    @RequiresApi(11)TODO:EasingFunction
//    private Animator xAnimator(int duration, EasingFunction easing) {
//
//        ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "phaseX", 0f, 1f);
//        animatorX.setInterpolator(easing);
//        animatorX.setDuration(duration);
//
//        return animatorX;
//    }

//    @RequiresApi(11)TODO:EasingFunction
//    private ObjectAnimator yAnimator(int duration, EasingFunction easing) {
//
//        ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
//        animatorY.setInterpolator(easing);
//        animatorY.setDuration(duration);
//
//        return animatorY;
//    }



    //TODO:其余方法

    /**
     * Gets the Y axis phase of the animation.
     *
     * @return float value of {@link #mPhaseY}
     */
    public float getPhaseY() {
        return mPhaseY;
    }

    /**
     * Sets the Y axis phase of the animation.
     *
     * @param phase float value between 0 - 1
     */
    public void setPhaseY(float phase) {
        if (phase > 1f) {
            phase = 1f;
        } else if (phase < 0f) {
            phase = 0f;
        }
        mPhaseY = phase;
    }

    /**
     * Gets the X axis phase of the animation.
     *
     * @return float value of {@link #mPhaseX}
     */
    public float getPhaseX() {
        return mPhaseX;
    }

    /**
     * Sets the X axis phase of the animation.
     *
     * @param phase float value between 0 - 1
     */
    public void setPhaseX(float phase) {
        if (phase > 1f) {
            phase = 1f;
        } else if (phase < 0f) {
            phase = 0f;
        }
        mPhaseX = phase;
    }
}
